package com.mage.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mage.mapper.UserMapper;
import com.mage.model.User;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class UserService {

    @Resource
    private UserMapper userMapper;

    public int insert(User user) {
        int i = userMapper.insert(user);
        return i;
    }

    public int delete(Integer id) {
        int count = userMapper.delete(id);
        return count;
    }

    public int update(User user) {
        int count = userMapper.update(user);
        return count;
    }

    public User  findById(Integer id) {
        User user = userMapper.findById(id);
        return user;

    }

    public List<User> find() {
        List<User> users = userMapper.find();
        return users;
    }

    public PageInfo<User> selectForPage(Integer page, Integer size) {
        if (page == null) {
            page = 1;
        }
        if (size == null) {
            size = 10;
        }
        PageHelper.startPage(page, size);

        List<User> users = userMapper.find();

        PageInfo<User> userPageInfo = new PageInfo<>(users);
        return userPageInfo;

    }
}
